﻿Public Class DRUGAGENTCVFCLASS
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Private ACVFID As Integer = Nothing
    Private AGENTCODE As String = Nothing
    Private PRDCODE As Integer = Nothing
    Private CVF As Integer = Nothing
    Private DEALQUAN As Integer = Nothing
    Private EXTRAQUAN As Integer = Nothing
    Private EXTRACVF As Integer = Nothing
    Private EXTRAUNIT As Integer = Nothing
    Private DISCOUNT As String = Nothing
    Private UNITID As Integer = Nothing
    Private AGENTPRC As Double = Nothing
    Private COMMENT As String = Nothing
    Private STATUS = Nothing
    Private SEQ As Integer = Nothing
    Private selectAgentCVF As String = "SELECT a.`acvfid` AS 'รหัสสินค้าที่ขายโดยผู้ค้า', a.`agentcode` AS 'รหัสผู้ค้า', b.`company_name` AS 'ชื่อผู้ค้า', a.`prdcode` AS 'รหัสผลิตภัณฑ์', c.`prdname` AS 'ชื่อผลิตภัณฑ์', a.`cvf` AS 'ขนาดบรรจุ', a.`dealquan` AS 'จำนวนที่ได้ของแถม', a.`extraquan` AS 'จำนวนแถม', a.`extracvf` AS 'ขนาดบรรจุ(แถม)', a.`extraunit` AS 'รหัสหน่วยของแถม', e.`unitname_th` AS 'หน่วยของแถม', a.`discount` AS 'ส่วนลด', a.`unitid` AS 'รหัสหน่วยนับ', a.`agentprc` AS 'ราคา', d.`unitname_th` AS 'หน่วยนับ', a.`seq` as 'ลำดับการซื้อ', a.`comment` AS 'หมายเหตุ', a.`status` AS 'สถานะการเปิดใช้งาน' FROM agentcvf a LEFT JOIN agent b ON a.agentcode = b.agentcode LEFT JOIN masproduct c ON a.prdcode = c.prdcode LEFT JOIN masunit d ON a.unitid = d.unitid LEFT JOIN masunit e ON a.extraunit = e.unitid"

    Public Property ACVFID_ As Integer
        Get
            Return ACVFID
        End Get
        Set(value As Integer)
            ACVFID = value
        End Set
    End Property

    Public Property AGENTCODE_ As String
        Get
            Return AGENTCODE
        End Get
        Set(value As String)
            AGENTCODE = value
        End Set
    End Property

    Public Property PRDCODE_ As Integer
        Get
            Return PRDCODE
        End Get
        Set(value As Integer)
            PRDCODE = value
        End Set
    End Property

    Public Property CVF_ As Integer
        Get
            Return CVF
        End Get
        Set(value As Integer)
            CVF = value
        End Set
    End Property

    Public Property DEALQUAN_ As Integer
        Get
            Return DEALQUAN
        End Get
        Set(value As Integer)
            DEALQUAN = value
        End Set
    End Property

    Public Property EXTRAQUAN_ As Integer
        Get
            Return EXTRAQUAN
        End Get
        Set(value As Integer)
            EXTRAQUAN = value
        End Set
    End Property

    Public Property EXTRACVF_ As Integer
        Get
            Return EXTRACVF
        End Get
        Set(value As Integer)
            EXTRACVF = value
        End Set
    End Property

    Public Property EXTRAUNIT_ As Integer
        Get
            Return EXTRAUNIT
        End Get
        Set(value As Integer)
            EXTRAUNIT = value
        End Set
    End Property

    Public Property DISCOUNT_ As String
        Get
            Return DISCOUNT
        End Get
        Set(value As String)
            DISCOUNT = value
        End Set
    End Property

    Public Property UNITID_ As Integer
        Get
            Return UNITID
        End Get
        Set(value As Integer)
            UNITID = value
        End Set
    End Property

    Public Property AGENTPRC_ As Double
        Get
            Return AGENTPRC
        End Get
        Set(value As Double)
            AGENTPRC = value
        End Set
    End Property

    Public Property COMMENT_ As String
        Get
            Return COMMENT
        End Get
        Set(value As String)
            COMMENT = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Public Property SEQ_ As Integer
        Get
            Return SEQ
        End Get
        Set(value As Integer)
            SEQ = value
        End Set
    End Property

    Public Property selectAgentCVF_ As String
        Get
            Return selectAgentCVF
        End Get
        Set(value As String)

        End Set
    End Property

    Public Function insertAgentCVF() As Boolean
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()

            connect.ExecuteNonQuery("INSERT INTO agentcvf (agentcode, prdcode, cvf, dealquan, extraquan, extracvf, extraunit, discount, unitid, agentprc, comment, seq, status) VALUES ('" & AGENTCODE & "', '" & PRDCODE & "', '" & CVF & "', '" & DEALQUAN & "', '" & EXTRAQUAN & "', '" & EXTRACVF & "', '" & EXTRAUNIT & "', '" & DISCOUNT & "', '" & UNITID & "', '" & AGENTPRC & "', '" & COMMENT & "', '" & SEQ & "', '" & STATUS & "')")
            'connectlocal.ExecuteNonQuery("INSERT INTO MASCOUNTRY ([CODECOUNTRY], [COUNTRY]) VALUES (" & countryCODECOUNTRY & ", '" & countryCOUNTRY & "');")
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลสินค้าที่ขายโดยผู้ค้าเรียบร้อยแล้ว")

            Return True
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
            Return False
        End Try
        'connectlocal.Dispose()
        connect.Dispose()
    End Function

    Public Function editAgentCVF() As Boolean
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()

            connect.ExecuteScalar("UPDATE agentcvf SET agentcode = '" & AGENTCODE & "', prdcode = '" & PRDCODE & "', cvf = '" & CVF & "', dealquan = '" & DEALQUAN & "', extraquan = '" & EXTRAQUAN & "', extracvf = '" & EXTRACVF & "', extraunit = '" & EXTRAUNIT & "', discount = '" & DISCOUNT & "', unitid = '" & UNITID & "', agentprc = '" & AGENTPRC & "', comment = '" & COMMENT & "',  seq = '" & SEQ & "', status = '" & STATUS & "' WHERE acvfid = '" & ACVFID & "'")
            'connectlocal.ExecuteNonQuery("INSERT INTO MASCOUNTRY ([CODECOUNTRY], [COUNTRY]) VALUES (" & countryCODECOUNTRY & ", '" & countryCOUNTRY & "');")
            MsgBox("ท่านได้ทำการแก้ไขข้อมูลสินค้าที่ขายโดยผู้ค้าเรียบร้อยแล้ว")

            Return True
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
            Return False
        End Try
        'connectlocal.Dispose()
        connect.Dispose()
    End Function
End Class
